package com.woke.adapter;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bean.TabColumn;
import com.zhongcai.online.BR;
import com.zhongcai.online.R;

import me.drakeet.multitype.ItemViewProvider;


/**
 * 作者 ： 暗网
 * 创建时间：2017/2/17
 * 备注： TabHomeFragment 栏目
 */

public class TabHomeColumnViewProvider extends ItemViewProvider<TabColumn, TabHomeColumnViewProvider.ViewHolder> {

	private OnItemClickListener mItemClickListener;

	public TabHomeColumnViewProvider(OnItemClickListener listener) {
		mItemClickListener = listener;
	}

	@NonNull
	@Override
	protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
		ViewDataBinding binding = DataBindingUtil.inflate (inflater, R.layout.fragment_tab_home_column, parent, false);

		ViewHolder holder = new ViewHolder (binding.getRoot ());
		holder.setBinding (binding);
		return holder;
	}

	@Override
	protected void onBindViewHolder(@NonNull final ViewHolder holder, @NonNull final TabColumn tabColumn) {
		holder.getBinding ().setVariable (BR.column, tabColumn);
		holder.getBinding ().executePendingBindings ();
		holder.itemView.setOnClickListener (new View.OnClickListener () {
			@Override
			public void onClick(View view) {
				if (mItemClickListener != null) {
					mItemClickListener.OnItemClick (view, tabColumn, getPosition (holder));
				}
			}
		});

        if(!TextUtils.isEmpty(tabColumn.getRemark())){
            holder.mCashBackTv.setVisibility(View.VISIBLE);
        }else{
            holder.mCashBackTv.setVisibility(View.INVISIBLE);
        }
	}

	class ViewHolder extends RecyclerView.ViewHolder {
		private ViewDataBinding binding;
		private TextView mCashBackTv;
		public ViewHolder(View itemView) {
			super (itemView);
			mCashBackTv= (TextView) itemView.findViewById(R.id.cash_back_tv);
		}

		public ViewDataBinding getBinding() {
			return binding;
		}

		public void setBinding(ViewDataBinding binding) {
			this.binding = binding;
		}


	}
}
